//
//  ZYStatus.swift
//  weiboZY
//
//  Created by 赵勇 on 16/5/13.
//  Copyright © 2016年 赵勇. All rights reserved.
//

import UIKit

// 微博数据模型
class ZYStatus: NSObject {

    //  微博创建时间
    var created_at: String?
    //  微博ID
    var id: Int64 = 0
    // 	微博信息内容
    var text:String?
    //  微博来源
    var source:String?
    //  用户模型
    var user: ZYUser?
    //  转发微博模型
    var retweeted_status: ZYStatus?
    //  转发数
    var reposts_count: Int = 0
    //  评论数
    var comments_count: Int = 0
    //  表态数
    var attitudes_count: Int = 0
    //  配图数据
    var pic_urls: [ZYStatusPictureInfo]?
    
    init(dict:[String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            
            user = ZYUser(dict: dict)
            
        } else if key == "retweeted_status" {
                guard let dict = value as? [String: AnyObject] else {
                    return
                }
                retweeted_status = ZYStatus(dict: dict)
            
        } else if key == "pic_urls" {
            
            guard let dictArray = value as? [[String: AnyObject]] else {
                return
            }
            
            var tempArray = [ZYStatusPictureInfo]()
            
           // 遍历字典数组
            for dic in dictArray {
                
                let picInfo = ZYStatusPictureInfo(dict: dic)
                tempArray.append(picInfo)
                
            }
            pic_urls = tempArray
            
        } else {
            
            super.setValue(value, forKey: key)
            
        }
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
